#!/usr/local/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/9/17 18:25
# @Author  : Kyy
# @Site    : 
# @File    : get_stock.py
# @Software: PyCharm

import requests
import demjson

def getall(p):
    res = requests.get("http://nufm.dfcfw.com/EM_Finance2014NumericApplication/JS.aspx?type=ct&st=(BalFlowMain)&sr=-1&p=" + str(p) + "&ps=50&js=var%20DPvVJMIR={pages:(pc),date:%222014-10-22%22,data:[(x)]}&token=894050c76af8597a853f5b408b759f5d&cmd=C._A&sty=DCFFITA&rt=51239325")
    rst = res.text
    rst2 = rst.replace("var DPvVJMIR=","")
    rst3 = demjson.decode(rst2)
    # print(rst3['data'])
    rst4 = rst3['data']
    rst5 = [tuple(item.split(',')[1:3]) for item in rst4]
    print(rst5)
    return rst5

allrst = []
for i in range(1,73):
    rst = getall(i)
    allrst.extend(rst)
print(allrst)

with open("stock.txt",'w') as f:
    for  i in allrst:
        f.write(str(i))
        f.write('/n')
